<template>
	<view>
		<u-navbar :is-back="true" :title="title"></u-navbar>
		<view class="VerticalBox">
			<scroll-view class="VerticalNav nav" scroll-y scroll-with-animation :scroll-top="verticalNavTop"
				:style="[{'height':viewitwm}]">
				<view class="cu-item" :class="index==tabCur?'text-black cur':'text-gray'" v-for="(item,index) in list"
					:key="index" @tap="TabSelect" :data-id="index">
					<image src="../../static/img/ic-tab-all.png" class="logo"></image>
					<view>{{item.name}}</view>
				</view>
			</scroll-view>
			<scroll-view class="VerticalMain" scroll-y scroll-with-animation :style="[{'height':viewitwm}]"
				:scroll-into-view="'main-'+mainCur" @scroll="VerticalMain">
				<view class="" v-for="(item,index) in list" :key="index" :id="'main-'+index">
					<view class="cu-list">
						<view class="cu-item u-flex u-row-between" v-for="(obj,findex) in item.arr" v-if="item.arr" @click="detail(obj,findex)">
							<view class="  ">
								<image :src="obj.url" class="avatar round"></image>
							</view>
							<view class="content">
								<view class="name">{{obj.name}}</view>
								<view class="produce">
									{{obj.produce}}
								</view>
							</view>

						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				viewitwm:0,
				list: [{
						id: 0,
						name: "全部",
						arr: [{
							id:11,
							name: "王小二",
							flag: true,
							url: "https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg",
							produce: "我已天理为凭，踏入这片荒芜，不再受凡人的枷锁遏制。我已天理为凭，踏入这片荒芜，不再受凡人的枷锁遏制",
						}]

					},
					{
						id: 1,
						name: "建筑施工"
					},
					{
						id: 2,
						name: "房地产开发"
					},
					{
						id: 3,
						name: "商贸"
					},
					{
						id: 4,
						name: "科技"
					},
					{
						id: 5,
						name: "网络直播"
					},
					{
						id: 6,
						name: "医美"
					},
				],
				tabCur: 0,
				mainCur: 0,
				verticalNavTop: 0,
				load: true,
				title: "全部老师",
			};
		},
		onLoad() {
			let systemInfo=uni.getSystemInfoSync();
			let statusBarHeight=systemInfo.windowHeight - (systemInfo.statusBarHeight+uni.upx2px(88))-10;
			this.viewitwm=statusBarHeight+"px";
			uni.showLoading({
				title: '加载中...',
				mask: true
			});

		},
		onReady() {
			uni.hideLoading()
		},
		methods: {
			detail(obj,index){
				uni.navigateTo({
					url:"/pages/verticalnav/teacher-detail?id=" + obj.id
				})
			},
			TabSelect(e) {
				this.tabCur = e.currentTarget.dataset.id;
				this.mainCur = e.currentTarget.dataset.id;
				this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 70
			},
			VerticalMain(e) {
				// #ifdef MP-ALIPAY
				return false //支付宝小程序暂时不支持双向联动 
				// #endif
				let that = this;
				let tabHeight = 0;
				if (this.load) {
					for (let i = 0; i < this.list.length; i++) {
						let view = uni.createSelectorQuery().select("#main-" + this.list[i].id);
						view.fields({
							size: true
						}, data => {
							this.list[i].top = tabHeight;
							tabHeight = tabHeight + data.height;
							this.list[i].bottom = tabHeight;
						}).exec();
					}
					this.load = false
				}
				let scrollTop = e.detail.scrollTop + 10;
				for (let i = 0; i < this.list.length; i++) {
					if (scrollTop > this.list[i].top && scrollTop < this.list[i].bottom) {
						this.verticalNavTop = (this.list[i].id - 1) * 70
						this.tabCur = this.list[i].id
						console.log(scrollTop)
						return false
					}
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	.VerticalNav.nav {
		width: 200upx;
		white-space: initial;
		background-color: #F1F2F3;
	}

	.VerticalNav.nav .cu-item {
		width: 100%;
		text-align: center;

		margin: 0;
		border: none;
		height: 70px;
		position: relative;

		.logo {
			width: 40rpx;
			height: 40rpx;
			margin-top: 30rpx;
		}
	}

	/deep/.nav .cu-item {
		line-height: 30rpx;
	}

	.VerticalNav.nav .cu-item.cur {
		background-color: #ffffff;
	}

	.VerticalNav.nav .cu-item.cur::after {
		content: "";
		width: 8upx;
		height: 100%;
		position: absolute;
		background-color: #FF9240;
		top: 0;
		left: 0upx;
		bottom: 0;

	}

	.VerticalBox {
		display: flex;
	}

	.VerticalMain {
		background-color: #ffffff;
		flex: 1;

		.cu-item {
			width: calc(100% - 40rpx);
			padding: 20rpx 0;
			margin: 0 20rpx;
			border-bottom: 1rpx solid #DBDDE0;
			.avatar {
				width: 144rpx;
				height: 144rpx;
			}

			.content {
				width: calc(100% - 144rpx);
				margin-left: 20rpx;
				font-size: 24rpx;
				color: #666666;
				
				.name {
					font-size: 32rpx;
					font-weight: 500;
					color: #333333;
					margin-bottom: 15rpx;
				}
				.produce{
					max-height: 64rpx;
					overflow: hidden;
				}
			}
		}
	}

	.text-gray {
		color: #888888;
	}
</style>
